<?php

class StatementForm extends BaseForm {

    public function __construct() {
        parent::__construct();
    }

    public function setup() {
        $customers = $this->getCustomersFormatted();
        $lines = $this->getLinesFormatted();
        
        $this->setWidgets(array(
            'customer_id' => new sfWidgetFormChoice(array('choices' => $customers)),
            'line_id' => new sfWidgetFormChoice(array('choices' => $lines)),
            'fromDate' => new sfWidgetFormInputText(),
            'toDate' => new sfWidgetFormInputText()
        ));


        $this->setValidators(array(
            'customer_id' => new sfValidatorChoice(array('choices' => array_keys($customers), 'required' => true), array('invalid' => 'Invalid Customer Name.', 'required' => 'Please enter required field.')),
            'line_id' => new sfValidatorChoice(array('choices' => array_keys($lines), 'required' => false), array('invalid' => 'Invalid Company Name.', 'required' => 'Please enter required field.')),
            'fromDate' => new sfValidatorString(array('required' => false), array('invalid' => 'Invalid Date.', 'required' => 'Please enter required field.')),
            'toDate' => new sfValidatorString(array('required' => false), array('invalid' => 'Invalid Date.', 'required' => 'Please enter required field.'))
        ));


        $this->widgetSchema->setNameFormat('statement[%s]');
    }

    private function getCustomersFormatted() {
        $bank_accounts = Doctrine_Query::create()->from('Customer')->where('is_deleted=?', 0)->orderBy('customer_name')->fetchArray();
        $result = array('' => '');

        foreach ($bank_accounts as $bank_account) {
            $result[$bank_account['id']] = $bank_account['customer_name'];
        }
        return $result;
    }
private function getLinesFormatted() {
        $bank_accounts = Doctrine::getTable("Line")->findAll();
        $result = array('' => '');
        
        foreach ($bank_accounts as $bank_account) {
            $result[$bank_account['id']] = $bank_account['name'];
        }
        
        return $result;
    }
}

?>
